package com.vip.elastic.service.impl;

import com.vip.common.response.ErrorCode;
import com.vip.common.response.Result;
import com.vip.common.response.Results;
import com.vip.elastic.service.IIndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Service;

/**
 * 索引管理
 *
 * @author wgb
 * @date 2020/11/10 10:52
 */
@Slf4j
@Service
public class IndexServiceImpl implements IIndexService {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchTemplate;

    @Override
    public Result<String> deleteIndex(String index) {
        try {
            elasticsearchTemplate.deleteIndex(index);
            return Results.newSuccessResult(null, "删除成功");
        } catch (Exception e) {
            log.error("索引删除出错", e);
        }
        return Results.newFailResult(ErrorCode.SYSTEM_ERROR, "删除失败");
    }

}
